<template>
    <div>
        <el-row style="margin:20px;">
            <el-checkbox-group v-model="CheckList">
                <el-row v-for="Mitem in planCategoryArr" :key="Mitem.index" class="plan-row">
                    <div>方案大类:{{Mitem.planCategoryName}}</div>
                    <div v-for="item in Mitem.sysPlans" :key="item.planId">
                        <el-col :span="1">
                            <el-checkbox :label="item.planId">{{null}}</el-checkbox>
                        </el-col>
                        <el-col :span="5">
                            <span>方案名称:</span>
                            <el-input class="special-red" size="mini" style="width:140px;" v-model="item.medicalEquipment"
                                placeholder="请输入方案名称"></el-input>
                        </el-col>
                        <el-col :span="4">
                            用法:<el-select v-model="item.usageId" placeholder="请选择用法" size="mini" style="width:120px">
                                <el-option v-for="dict in dict.type.sys_plan_usage" :key="dict.value" :label="dict.label"
                                    :value="dict.value"></el-option>
                            </el-select>
                        </el-col>
                        <el-col :span="4">
                            用量:<el-input size="mini" style="width:120px" v-model="item.dosage"
                                placeholder="请输入用量"></el-input>
                        </el-col>
                        <el-col :span="4">
                            单位:<el-select size="mini" style="width:120px" v-model="item.dosageUnit" placeholder="请选择用量单位">
                                <el-option v-for="dict in dict.type.sys_dosage_unit" :key="dict.value" :label="dict.label"
                                    :value="dict.value"></el-option>
                            </el-select>
                        </el-col>
                        <el-col :span="4">
                            频次:<el-select size="mini" style="width:120px" v-model="item.frequencyId" placeholder="请选择频次">
                                <el-option v-for="dict in dict.type.sys_dosage_frequency" :key="dict.value"
                                    :label="dict.label" :value="dict.value"></el-option>
                            </el-select>
                        </el-col>
                        <el-col :span="2">
                            数量:<el-input size="mini" style="width:60px" v-model="item.num" placeholder="请输入数量"></el-input>
                        </el-col>
                    </div>
                </el-row>
            </el-checkbox-group>
        </el-row>
        <div style="width: 130px;margin:0 auto">
            <el-button type="primary" @click="cancel" size="mini">取 消</el-button>
            <el-button type="primary" @click="savePlan" size="mini">确 定</el-button>
        </div>

    </div>
</template>

<script>
import {
    batchAddPatientPlan,
    batchUpdatePatientPlan,
} from "@/api/patients/personal";
export default {
    name: "plan",
    props: ["planCategoryData", "patientId", "visitId", "addOrUpdate"],
    dicts: [
        "sys_plan_category",
        "sys_user_sex",
        "sys_manage_diseases",
        "sys_diagnosis_status",
        "photo_upload_type",
        "photo_lighting_type",
        "sys_dosage_unit",
        "sys_dosage_frequency",
        "sys_plan_usage",
    ],
    data() {
        return {
            CheckList: [],
            planCategoryArr: this.planCategoryData,
        };
    },
    mounted() {
        console.log("111111111111111111", this.planCategoryData);
    },
    methods: {
        cancel() {
            this.$emit("closePlanPage");
        },
        savePlan() {
            if (this.addOrUpdate === 1) {
                if (this.CheckList.length > 0) {
                    let planArr = [];
                    this.CheckList.forEach((item) => {
                        this.planCategoryData.forEach((it) => {
                            it.sysPlans.forEach((Mit) => {
                                Mit.patientId = this.patientId;
                                Mit.visitId = this.visitId;
                                if (item == Mit.planId) {
                                    planArr.push(Mit);
                                }
                            });
                        });
                    });
                    planArr.forEach((itSelf) => {
                        delete itSelf.planId;
                        delete itSelf.createTime;
                        delete itSelf.updateTime;
                        delete itSelf.createBy;
                    });

                    batchAddPatientPlan(planArr).then((res) => {
                        this.$emit("reFreshPlanList");
                        this.$message.success("方案已经提交");
                    });
                } else {
                    this.$message.warning("请至少选择一项方案");
                }
            }
            if (this.addOrUpdate === 2) {
                let planArr = [];
                this.planCategoryData.forEach((it) => {
                    it.sysPlans.forEach((Mit) => {
                        Mit.patientId = this.patientId;
                        Mit.visitId = this.visitId;
                        planArr.push(Mit);
                    });
                });
                batchUpdatePatientPlan(planArr).then((res) => {
                    this.$emit("reFreshPlanList");
                    this.$message.success("方案已经提交");
                });
            }
        },
    },
};
</script>
<style scoped>
.el-checkbox-group {
    font-size: 14px;
}

/deep/ .special-red .el-input__inner {
    color: red;
}

.plan-row {
    font-size: 18px;
}

/deep/ .el-input__inner {
    font-size: 18px;
}

/deep/ .el-checkbox__inner {
    border: 1px solid blue;
}
</style>